var eventData = {ids:null,len:0,index:0,status:"init"};
$(function(){
	init();
}); 

function init(){
	getevent();
}

getevent = function(){
	//获取活动信息
	if(eventData.status=="init"){
		eventData.status = "get";
		cb = function (data){
			if(data.code==1){
				eventData.ids = data.data;
				eventData.len = data.data.length;
				$(".user_list").empty();
				$(".follow_list").empty();
				$(".user_list").html("<span class='label'>努力加载中...</span>");
				showuser();
			}else{
				$(".user_list").html("<span class='label'>没有活动相关信息,请马上<a style='color:yellow;' href='"+site.web+"my/cparty'>创建</a>活动.</span>");
			}
		}
		var url = site.web+"my/event/geteventbyuser";
		var json = {url:url,uid:site.uid};
		G(json,cb);
	}
	
}

showuser = function(){
	if(eventData.ids){
		$(".user_list").empty();
		$(".follow_list").empty();
		$(".user_list").html("<span class='label'>努力加载中...</span>");
		
		
		cb = function (data){
			if(data.code==1){
				var user = data.data.user,
					follow = data.data.follow,
					event = data.data.event,
					ulist = "",
					flist = "";
				//set user
				if(user.length!=0){
					$.each(user,function(index,value){
						var path = site.web+user[index]['fileimg'];
						ulist += "<li><img src='"+path+"'/></li>";
					});
					$(".user_list").empty();
					$(".user_list").append("<span class='label label-info'>来宾:共"+user.length+"人</span>");
					$(".user_list").append("<ul>"+ulist+"</ul>");
				}else{
					$(".user_list").empty();
					$(".user_list").append("<span class='label'>活动暂时没有来宾信息</span>");
				}
				
				//set follower
				if(follow.length!=0){
					$.each(follow,function(index,value){
						var name = follow[index]['nickname'];
						if(!name)name='--';
						flist += "<li><span class='label margin5'>"+name+"</span></li>";
					});
					$(".follow_list").empty();
					$(".follow_list").append("<span class='label label-success'>关注者:共"+follow.length+"人</span>");
					$(".follow_list").append("<ul>"+flist+"</ul>");
				}else{
					$(".follow_list").empty();
					$(".follow_list").append("<span class='label'>活动暂时没有关注者信息</span>");
				}
				
				//set event
				$(".label_name").text(event.title);
				$(".label_date").text("活动时间:"+timeformat(event.startdate,4)+" ~ "+timeformat(event.enddate,6));
				
			}else{
				alert("ERROR gallery 404");
			}
		}
		var url = site.web+"my/eventuser/get";
		var json = {url:url,uid:site.uid,eid:eventData.ids[eventData.index]};
		if(eventData.index==eventData.len-1){
			eventData.index = 0;
		}else{
			eventData.index ++;
		}
		G(json,cb);
	}
}
